package com.spark.check

import android.os.Bundle
import android.support.annotation.LayoutRes
import android.support.v7.widget.LinearLayoutManager
import android.view.View
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.spark.check.model.CheckHistoryModel
import com.spark.common.BaseFragment
import kotlinx.android.synthetic.main.frag_check_history.*

/**
 * 标化检查历史
 */
class StdChkHistoryFragment : BaseFragment() {
    companion object {
        fun newInstance(): StdChkHistoryFragment {
            val fragment = StdChkHistoryFragment()
            val args = Bundle()

            fragment.arguments = args
            return fragment
        }
    }

    private lateinit var checkHistoryAdapter: CheckHistoryAdapter

    override fun contentResId(): Int {
        return R.layout.frag_check_history
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        iv_back.setOnClickListener { pop() }

        checkHistoryAdapter = CheckHistoryAdapter(R.layout.item_check_history)
        recy_chk_history.adapter = checkHistoryAdapter
        recy_chk_history.layoutManager = LinearLayoutManager(context)

        checkHistoryAdapter.addData(CheckHistoryModel.Data.TaskItem())

        checkHistoryAdapter.addData(mutableListOf(
                CheckHistoryModel.Data.TaskItem(),
                CheckHistoryModel.Data.TaskItem(),
                CheckHistoryModel.Data.TaskItem(),
                CheckHistoryModel.Data.TaskItem(),
                CheckHistoryModel.Data.TaskItem(),
                CheckHistoryModel.Data.TaskItem(),
                CheckHistoryModel.Data.TaskItem(),
                CheckHistoryModel.Data.TaskItem(),
                CheckHistoryModel.Data.TaskItem(),
                CheckHistoryModel.Data.TaskItem()
        ))
    }
}

class CheckHistoryAdapter(@LayoutRes layoutRes: Int) : BaseQuickAdapter<CheckHistoryModel.Data.TaskItem, BaseViewHolder>(layoutRes) {
    override fun convert(helper: BaseViewHolder?, item: CheckHistoryModel.Data.TaskItem?) {
        if (item == null) return
        helper?.apply {
            setText(R.id.tv_name, item.categoryname)
        }
    }

}